package com.liuyan.service.impl;

import com.liuyan.dao.IContentDao;
import com.liuyan.pojo.Content;
import com.liuyan.service.IContentService;
import com.liuyan.util.CommonConstants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by pc on 2016/1/5.
 */
@Service("contentService")
@Transactional
public class ContentServiceImpl implements IContentService {
    @Resource
    private IContentDao iContentDao;

    @Override
    public boolean writeContent(Content contentBean) {
        int i = 0;
        i = this.iContentDao.writeContent(contentBean);
        return (i>0)?true:false;
    }

    @Override
    public int getMaxFloor() {
        return this.iContentDao.getMaxFloor();
    }

    @Override
    public boolean deleteContent(int contentId) {
        int i = 0;
        i = this.iContentDao.deleteContent(contentId);
        return (i>0)?true:false;
    }

    @Override
    public int getAllCount() {
        return iContentDao.getAllCount();
    }

    @Override
    public List<Content> contentListForLevelOne() {
        int pageSize = CommonConstants.PAGESIZE;
        return  this.iContentDao.contentListForLevelOne(pageSize);
    }

    @Override
    public List<Content> contentListForLevelTwo() {
        int pageSize = CommonConstants.PAGESIZE;
        return  this.iContentDao.contentListForLevelTwo(pageSize);
    }

    @Override
    public List<Content> getContentOfPageForLevelOne(int currentPage) {
        int pageNo = (currentPage - 1)* CommonConstants.PAGESIZE;
        int pageSize = CommonConstants.PAGESIZE;
        Map<Object,Integer> map = new HashMap<>();
        map.put("pageNo",pageNo);
        map.put("pageSize",pageSize);
        return this.iContentDao.getContentOfPageForLevelOne(map);
    }

    @Override
    public List<Content> getContentOfPageForLevelTwo(int currentPage) {
        int pageNo = (currentPage - 1)*CommonConstants.PAGESIZE;
        int pageSize = CommonConstants.PAGESIZE;
        Map<Object,Integer> map = new HashMap<>();
        map.put("pageNo",pageNo);
        map.put("pageSize",pageSize);
        return this.iContentDao.getContentOfPageForLevelTwo(map);
    }

    @Override
    public int getLevelByContentId(int contentId) {
        return this.iContentDao.getLevelByContentId(contentId);
    }

    @Override
    public boolean deleteContentByFloor(int contentId) {
        int i = 0;
        i = this.iContentDao.deleteContentByFloor(contentId);
        return (i>0)?true:false;
    }

}
